package cn.zhangfusheng.api.ui.controller;

import cn.zhangfusheng.api.ui.util.HttpClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URISyntaxException;

/**
 * @ClassName: ApiController
 * @Author: ZFS
 * @Date: 2018/10/22 12:21
 */
@RestController
public class ApiController {


    @Autowired
    HttpClientUtils httpClientUtils;

    /**
     * swagger 基础API访问
     *
     * @param agreement 协议
     * @param domain    域名
     * @param port      端口号
     * @param path      访问路径
     * @param request   请求
     * @param response  响应
     * @return string
     * @throws IOException IOException
     */
    @GetMapping("getBasic")
    public String getBasic(@RequestParam(required = false, defaultValue = "http") String agreement,
                           @RequestParam(required = true, defaultValue = "localhost") String domain,
                           @RequestParam(required = false, defaultValue = "80") String port,
                           @RequestParam(required = true, defaultValue = "/") String path,
                           @RequestParam(required = true, defaultValue = "GET") String method,
                           @RequestParam(required = true, defaultValue = "") String param,
                           HttpServletRequest request, HttpServletResponse response) throws IOException, URISyntaxException {
        return httpClientUtils.requestUrl(agreement, domain, port, path, method, param, request, response);
    }
}
